package com.design.twords.adatper;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.design.twords.R;
import com.design.twords.database.Phrase_all;

import java.util.List;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

/**
 * Create by Alen
 * Time:  15:44
 */
public class PharseAdapter extends RecyclerView.Adapter<PharseAdapter.MyViewHolder>{

    private LayoutInflater myInflater;
    private Context context;
    private List<Phrase_all> pharses;
    private int viewId;
    private String booktype;

    public PharseAdapter(Context context, List<Phrase_all> pharses, int viewId, String booktype) {
        this.myInflater = LayoutInflater.from(context);
        this.context = context;
        this.pharses = pharses;
        this.viewId = viewId;
        this.booktype = booktype;
    }

    public void setPharses(List<Phrase_all> pharses) {
        this.pharses = pharses;
    }

    @NonNull
    @Override
    public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new MyViewHolder(myInflater.inflate(viewId, parent, false));
    }

    @Override
    public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
        Phrase_all phrase_all = pharses.get(position);
        holder.pharse_id.setText((position+1) + ":");
        holder.pharse_content.setText(phrase_all.getPhrase());
        holder.pharse_trans.setText(phrase_all.getTrans());

    }

    @Override
    public int getItemCount() {
        return pharses.size();
    }

    public class MyViewHolder extends RecyclerView.ViewHolder {
        private TextView pharse_id, pharse_content, pharse_trans;

        public MyViewHolder(@NonNull View itemView) {
            super(itemView);
            pharse_id = itemView.findViewById(R.id.pharse_id);
            pharse_content = itemView.findViewById(R.id.pharse_content);
            pharse_trans = itemView.findViewById(R.id.pharse_trans);
        }
    }
}
